/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
 #include<stdlib.h>
 int cmp (const void*p1,const void*p2)
 {
    return *(int*)p1-*(int*)p2;
 }
int* getSubarrayBeauty(int* nums, int numsSize, int k, int x, int* returnSize) {
    int ret=0;
    int*a=(int*)malloc(sizeof(int)*k);
    int*b=(int*)malloc(sizeof(int)*numsSize) ;
    for(int i=0;i<=numsSize-1;i++)
    {
        int pos=i;
        for(int j=0;j<k && pos<=numsSize-1;j++,pos++)
        {
            a[j]=nums[pos];
        }
        qsort(a,k,4,cmp);
        if(a[x-1]<0)
            b[i]=a[x-1];
        else
            b[i]=0;    
    }
    *returnSize=numsSize-k+1;
    return b;
}